package day017.exception;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class ExceptionTset {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入生日（****-**-**）");

        while(true){
            String birthday=sc.nextLine();
            try{
                method(birthday);
                break;
            }catch (ParseException e){
                System.out.println("录入生日格式有误！");
            }
        }
    }

    public static void method(String birthday) throws ParseException{
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=sdf.parse(birthday);

        long time1=date.getTime();
        Date d2=new Date();
        long time2=d2.getTime();

        System.out.println("活了"+(time2-time1)/(1000L*60*60*24)+"天");

    }
}
